package m202310.d30;

/**
 * @author haocongshun
 * @date 2023/10/30 19:03:32
 */

import java.util.ArrayList;
import java.util.List;

/**
 * 101. 对称二叉树
 * <p>
 * 给你一个二叉树的根节点 root ， 检查它是否轴对称。
 */
public class Q101 {

    public boolean isSymmetric(TreeNode root) {
        return travel(root.left, root.right);
    }

    public boolean travel(TreeNode left, TreeNode right) {
        if (left == null && right == null) {
            return true;
        } else if (left != null && right != null && left.val == right.val) {
            return travel(left.left, right.right) && travel(left.right, right.left);
        } else {
            return false;
        }
    }

    public static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

}
